<?php

namespace app\api\controller;


use app\api\model\MallUser;
use app\common\controller\IndexController;
use think\App;

use app\api\library\index\getBanner;
use app\api\library\index\getArticle;
use app\api\library\index\novicesGoods;
use app\api\library\index\goodsList;
use app\api\library\index\goodsDetail;
use app\api\library\index\getRule;
use app\api\library\index\getNoviceRule;
use app\api\library\index\collageGoods;
use app\api\library\index\collageDetail;
use app\api\library\index\getAddress;
use app\api\library\index\getUserAddress;
use app\api\library\index\getUserCurrentAddress;
use app\api\library\index\addUserAddress;
use app\api\library\index\updateUserAddress;
use app\api\library\index\deleteUserAddress;
use app\api\library\index\currentUserAddress;
use app\api\library\index\helpAndIns;

class Index extends IndexController
{
    
    public function makeVirtualUser()
    {
        
        $addData = [];
        for ($i = 0 ; $i < 10 ; $i++) {
            $avatarUrl = 'https://tg.aipintuangou.com/upload/avatar/aratar_' . rand(1, 1600) . '.jpg';
            $addData[] = [
                'avatar_url' => $avatarUrl,
                'is_virtual' => 1,
                'open_id'    => createOrderNo(),
                'nick_name'  => nickname(rand(1, 2)),
                'name'       => nickname(rand(1, 2)),
            ];
        }
        MallUser::insertAll($addData);
        
    }
    /**
     * 获取首页轮播图
     */
    public function getBanner()
    {
        header('Access-Control-Allow-Origin:*'); // *代表允许任何网址请求
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        getBanner\V::run($param);
    }
    /**
     * 获取首页轮播图
     */
    public function getArticle()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['articleId', 'ai', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        getArticle\V::run($param);
    }
    /**
     * 获取新手专属商品
     */
    public function novicesGoods()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['page', 'pe', 'int', 1],
            ['limit', 'lt', 'int', 3],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        novicesGoods\V::run($param);
    }
    /**
     * 获取商品列表
     */
    public function goodsList()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['sortType', 'st', 'int', 1],
            ['keywords', 'ks', 'str'],
            ['page', 'pe', 'int', 1],
            ['limit', 'lt', 'int', 3],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        goodsList\V::run($param);
    }
    /**
     * 获取商品详情
     */
    public function goodsDetail()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['goodsId', 'gi', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        goodsDetail\V::run($param);
    }
    /**
     * 获取拼团规则
     */
    public function getRule()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        getRule\V::run($param);
    }
    /**
     * 获取拼团规则
     */
    public function getNoviceRule()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        getNoviceRule\V::run($param);
    }
    /**
     * 获取拼团中的商品
     */
    public function collageGoods()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['keywords', 'ks', 'str'],
            ['page', 'pe', 'int', 1],
            ['limit', 'lt', 'int', 3],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        collageGoods\V::run($param);
    }
    /**
     * 获取拼团中的商品
     */
    public function collageDetail()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['collageId', 'ci', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        collageDetail\V::run($param);
    }
    /**
     * 获取地址列表
     */
    public function getAddress()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        getAddress\V::run();
    }
    /**
     * 获取用户地址信息
     */
    public function getUserAddress()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        getUserAddress\V::run($param);
    }
    /**
     * 获取用户地址信息
     */
    public function getUserCurrentAddress()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        
        
        getUserCurrentAddress\V::run($param);
    }
    /**
     * 添加用户地址信息
     */
    public function addUserAddress()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
            ['name', 'ne', 'str'],
            ['phone', 'ph', 'int'],
            ['province_id', 'pi', 'int'],
            ['province', 'pe', 'str'],
            ['city_id', 'ci', 'int'],
            ['city', 'cy', 'str'],
            ['region_id', 'ri', 'int'],
            ['region', 'rn', 'str'],
            ['district', 'di', 'str'],
            ['detail', 'dl', 'str'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        addUserAddress\V::run($param);
    }
    /**
     * 修改用户地址信息
     */
    public function updateUserAddress()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['id', 'id', 'int'],
            ['userId', 'ui', 'int'],
            ['name', 'ne', 'str'],
            ['phone', 'ph', 'int'],
            ['province_id', 'pi', 'int'],
            ['province', 'pe', 'str'],
            ['city_id', 'ci', 'int'],
            ['city', 'cy', 'str'],
            ['region_id', 'ri', 'int'],
            ['region', 'rn', 'str'],
            ['district', 'di', 'str'],
            ['detail', 'dl', 'str'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        updateUserAddress\V::run($param);
    }
    /**
     * 删除用户地址信息
     */
    public function deleteUserAddress()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['id', 'id', 'int'],
            ['userId', 'ui', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        deleteUserAddress\V::run($param);
    }
    /**
     * 设置默认地址
     */
    public function currentUserAddress()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['id', 'id', 'int'],
            ['userId', 'ui', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        currentUserAddress\V::run($param);
    }
    /**
     * 提现说明和使用帮助
     */
    public function helpAndIns()
    {
        $req = $this->run(WEB_KEY);
//        $req = request()->param();
        //处理参数
        $display = [
            ['userId', 'ui', 'int'],
        ];
        //校验参数
        $param = _displayParam($req, $display);
        helpAndIns\V::run($param);
    }
}
